//
//  WXPBannerWebVC.m
//  MexicoLoan
//
//  Created by wxp on 2025/4/14.
//
//

#import "WXPBannerWebVC.h"
#import <WebKit/WebKit.h>

@interface WXPBannerWebVC ()

@property (nonatomic, strong) WXPNavView * navView;
@property (nonatomic, strong) WKWebView * webView;

@end

@implementation WXPBannerWebVC

#pragma mark - lazy
- (WXPNavView *)navView
{
    if (_navView == nil) {
        _navView = [WXPNavView  new];
        _navView.btnService.hidden = true;
        _navView.titleLabel.textColor = COLOR_BLACK;
        [_navView resetViewWithTitle:@""];
    }
    return  _navView;
}
- (WKWebView *)webView
{
    if (_webView == nil) {
        // 配置
        WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] init];
        // 启用 JavaScript
        WKPreferences *preferences = [[WKPreferences alloc] init];
        preferences.javaScriptEnabled = YES;
        
        webViewConfiguration.preferences = preferences;

        // 启用 DOM 存储
        WKWebsiteDataStore *dataStore = [WKWebsiteDataStore defaultDataStore];
        webViewConfiguration.websiteDataStore = dataStore;
        
        _webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) configuration:webViewConfiguration];
        _webView.frame = CGRectMake(0, [GlobalMethod getNavgationBarHeight], SCREEN_WIDTH, SCREEN_HEIGHT-[GlobalMethod getNavgationBarHeight]);
        _webView.scrollView.bounces = NO;
        self.edgesForExtendedLayout = UIRectEdgeNone;
        // 配置html
        [_webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:self.htmlUrl]]];
    }
    return  _webView;
}

#pragma mark - viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    //添加导航栏
    [self addNav];
    
    //table
    self.tableHeaderTopBg.backgroundColor = [UIColor whiteColor];
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.webView];
    
    // 打点
    // [GlobalMethod userBehaviorRecordWithPageName:@"Agreement" action:@"Enter" extInfo:@{@"type":@"Loan"}];
}

#pragma mark - addNav
- (void)addNav{
    [self.view addSubview:self.navView];
}

@end
